home *** CD-ROM | disk | FTP | other *** search
- Public Class ProviderControlsForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
- Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
- Friend WithEvents HelpProvider1 As System.Windows.Forms.HelpProvider
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents Label2 As System.Windows.Forms.Label
- Friend WithEvents btnOK As System.Windows.Forms.Button
- Friend WithEvents btnCancel As System.Windows.Forms.Button
- Friend WithEvents txtProduct As System.Windows.Forms.TextBox
- Friend WithEvents txtQty As System.Windows.Forms.TextBox
- Private components As System.ComponentModel.IContainer
-
- 'Required by the Windows Form Designer
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.components = New System.ComponentModel.Container()
- Me.txtQty = New System.Windows.Forms.TextBox()
- Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
- Me.txtProduct = New System.Windows.Forms.TextBox()
- Me.btnOK = New System.Windows.Forms.Button()
- Me.btnCancel = New System.Windows.Forms.Button()
- Me.HelpProvider1 = New System.Windows.Forms.HelpProvider()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.Label2 = New System.Windows.Forms.Label()
- Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider()
- Me.SuspendLayout()
- '
- 'txtQty
- '
- Me.HelpProvider1.SetHelpString(Me.txtQty, "Insert the number of products to be order. It must be a number in the range 1-100" & _
- ".")
- Me.txtQty.Location = New System.Drawing.Point(28, 80)
- Me.txtQty.Name = "txtQty"
- Me.HelpProvider1.SetShowHelp(Me.txtQty, True)
- Me.txtQty.Size = New System.Drawing.Size(248, 24)
- Me.txtQty.TabIndex = 3
- Me.txtQty.Text = ""
- Me.ToolTip1.SetToolTip(Me.txtQty, "The number of products ordered")
- '
- 'txtProduct
- '
- Me.HelpProvider1.SetHelpString(Me.txtProduct, "Enter the name of the product. This field can't be empty.")
- Me.txtProduct.Location = New System.Drawing.Point(28, 32)
- Me.txtProduct.Name = "txtProduct"
- Me.HelpProvider1.SetShowHelp(Me.txtProduct, True)
- Me.txtProduct.Size = New System.Drawing.Size(248, 24)
- Me.txtProduct.TabIndex = 1
- Me.txtProduct.Text = ""
- Me.ToolTip1.SetToolTip(Me.txtProduct, "The name of the product")
- '
- 'btnOK
- '
- Me.btnOK.Location = New System.Drawing.Point(68, 120)
- Me.btnOK.Name = "btnOK"
- Me.btnOK.Size = New System.Drawing.Size(72, 32)
- Me.btnOK.TabIndex = 4
- Me.btnOK.Text = "OK"
- Me.ToolTip1.SetToolTip(Me.btnOK, "Click here to confirm the order")
- '
- 'btnCancel
- '
- Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
- Me.btnCancel.Location = New System.Drawing.Point(164, 120)
- Me.btnCancel.Name = "btnCancel"
- Me.btnCancel.Size = New System.Drawing.Size(72, 32)
- Me.btnCancel.TabIndex = 5
- Me.btnCancel.Text = "Cancel"
- Me.ToolTip1.SetToolTip(Me.btnCancel, "Click here to cancel the order")
- '
- 'Label1
- '
- Me.Label1.Location = New System.Drawing.Point(32, 16)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(120, 16)
- Me.Label1.TabIndex = 0
- Me.Label1.Text = "Product"
- '
- 'Label2
- '
- Me.Label2.Location = New System.Drawing.Point(32, 64)
- Me.Label2.Name = "Label2"
- Me.Label2.Size = New System.Drawing.Size(120, 16)
- Me.Label2.TabIndex = 2
- Me.Label2.Text = "Quantity"
- '
- 'ErrorProvider1
- '
- Me.ErrorProvider1.DataMember = Nothing
- '
- 'ProviderControlsForm
- '
- Me.AcceptButton = Me.btnOK
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.CancelButton = Me.btnCancel
- Me.ClientSize = New System.Drawing.Size(312, 165)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.Label2, Me.Label1, Me.txtQty, Me.txtProduct})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "ProviderControlsForm"
- Me.Text = "ProviderControls demo"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' display error icon near all controls that didn't validate
-
- Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
- ' assume it's ok to close the form.
- Me.DialogResult = DialogResult.OK
-
- ' clear all error icons.
- ErrorProvider1.SetError(txtProduct, "")
- ErrorProvider1.SetError(txtQty, "")
-
- ' validate the txtProduct control
-
- If txtProduct.Text = "" Then
- ErrorProvider1.SetError(txtProduct, "Must enter a product name")
- Me.DialogResult = DialogResult.None
- End If
-
- ' validate the txtQty field
-
- Try
- ' Attempt to get a valid quantity.
- Dim qty As Integer = CInt(txtQty.Text)
- ' Thown any error if out of range.
- If qty < 1 Or qty > 100 Then Throw New Exception()
- Catch
- ' Regardless of the error, use the same error message.
- ErrorProvider1.SetError(txtQty, "Enter a valid number in range 1-100")
- Me.DialogResult = DialogResult.None
- End Try
-
- ' exit only if DialogResult wasn't reset
- If Me.DialogResult = DialogResult.OK Then Me.Close()
- End Sub
-
- ' close anyway when clicking on the Cancel button
-
- Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- Me.Close()
- End Sub
- End Class
-